home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Pascal / Turbo Pascal 7.1 Final CD-RiP / EXAMPLES / TVFM / TVFM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-05  |  5.6 KB  |  240 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Vision File Manager Demo               }
  4. {   Copyright (c) 1992 by Borland International  }
  5. {                                                }
  6. {************************************************}
  7.  
  8. {$M 16384,8192,655360}
  9. {$X+,V-}
  10.  
  11. program TVFM;
  12.  
  13. uses Objects, Drivers, Memory, App, Views, Menus, Dialogs, StdDlg, Globals,
  14.   Gadgets, Dos, MsgBox, Equ, Tools, TreeWin, Colors, Assoc, Trash,
  15.   FileFind;
  16.  
  17. const
  18. {$IFDEF SingleExe}
  19.   RezExt = '.EXE';
  20. {$ELSE}
  21.   RezExt = '.TVR';
  22. {$ENDIF}
  23.  
  24. type
  25.  
  26.   TMyApp = object(TApplication)
  27.     Heap : PHeapView;
  28.     TrashCan: PTrashCan;
  29.     ExitDir: String;
  30.     constructor Init;
  31.     destructor Done; virtual;
  32.     procedure Idle; virtual;
  33.     procedure InitMenuBar; virtual;
  34.     procedure InitStatusLine; virtual;
  35.     procedure ToggleVideoMode;
  36.     procedure HandleEvent(var Event: TEvent); virtual;
  37.     procedure OutOfMemory; virtual;
  38.   end;
  39.  
  40.  
  41. { TMyApp implementation }
  42.  
  43. constructor TMyApp.Init;
  44. var
  45.   R: TRect;
  46.   H: Word;
  47.   CurDir: PathStr;
  48. begin
  49.   { Initialize resource file }
  50.  
  51.   RezStream := New(PProtectedStream, Init(GetExeBaseName + RezExt, stOpenRead, 4096));
  52.   if RezStream^.Status <> stOK then
  53.   begin
  54.     PrintStr('Unable to open resource file.');
  55.     Halt(1);
  56.   end;
  57.   RezFile.Init(RezStream);
  58.  
  59.   { Standard Turbo Vision objects }
  60.   RegisterObjects;
  61.   RegisterViews;
  62.   RegisterMenus;
  63.   RegisterDialogs;
  64.   RegisterApp;
  65.   RegisterStdDlg;
  66.  
  67.   { Objects specific to this app }
  68.   RegisterGlobals;
  69.   RegisterType(RStringList);
  70.   RegisterAssociations;
  71.  
  72.   RezStrings := PStringList(RezFile.Get('Strings'));
  73.  
  74.   if RezStrings = nil then
  75.   begin
  76.     PrintStr('Unable to read resources from resource file.');
  77.     Halt(1);
  78.   end;
  79.  
  80.   inherited Init;
  81.   InitAssociations;
  82.  
  83.   GetExtent(R);
  84.   Dec(R.B.X);
  85.   R.A.X := R.B.X - 9; R.A.Y := R.B.Y - 1;
  86.   Heap := New(PHeapView, Init(R));
  87.   Insert(Heap);
  88.  
  89.   Desktop^.GetExtent(R);
  90.   Dec(R.B.Y); Inc(R.A.X);
  91.   R.A.Y := R.B.Y - 3;
  92.   R.B.X := R.A.X + 5;
  93.   TrashCan := New(PTrashCan, Init(R));
  94.   with TrashCan^ do
  95.   begin
  96.     Options := Options or (ofSelectable + ofTopSelect);
  97.     EventMask := EventMask or evBroadcast;
  98.   end;
  99.   Desktop^.Insert(TrashCan);
  100.  
  101.   ConfigRec.Video := ScreenMode and smFont8x8;
  102.   ReadConfig;
  103.   if ConfigRec.Video <> (ScreenMode and smFont8x8) then
  104.     ToggleVideoMode;
  105.  
  106.   { by defaut, open a directory window to the current drive }
  107.   GetDir(0, CurDir);
  108.   InsertTreeWindow(CurDir[1]);
  109. end;
  110.  
  111. destructor TMyApp.Done;
  112. begin
  113.   DoneAssociations;
  114.   Dispose(Heap, Done);
  115.   Dispose(TrashCan, Done);
  116. {$I-}
  117.   if ExitDir <> '' then
  118.   begin
  119.     if ExitDir[Length(ExitDir)] = ':' then ExitDir := ExitDir + '\';
  120.     ChDir(ExitDir);
  121.   end;
  122. {$I+}
  123.   inherited Done;
  124.   DoneMemory;
  125. end;
  126.  
  127. procedure TMyApp.Idle;
  128. const
  129.   FileListCmds : TCommandSet =
  130.     [cmExecute, cmViewAsHex, cmViewAsText, cmViewCustom, cmCopy, cmDelete,
  131.      cmRename, cmChangeAttr, cmReverseTags, cmClearTags, cmTagPerCard,
  132.      cmAssociate];
  133. var
  134.   TopWindow: PWindow;
  135. begin
  136.   inherited Idle;
  137.  
  138.   TopWindow := Message(Desktop, evBroadcast, cmTopWindow, nil);
  139.   if TopWindow = nil then
  140.   begin
  141.     DisableCommands(FileListCmds);
  142.     DisableCommands([cmExitHere]);
  143.   end
  144.   else
  145.   begin
  146.     EnableCommands([cmExitHere]);
  147.     if Message(TopWindow, evBroadcast, cmFileListFocused, nil) <> nil then
  148.       EnableCommands(FileListCmds)
  149.     else
  150.       DisableCommands(FileListCmds);
  151.   end;
  152.  
  153.   { This app defines a new type of event, evIdle.  This event type is }
  154.   { generated once every idle cycle.                                  }
  155.   Message(Desktop, evIdle, 0, nil);
  156.  
  157.   if Heap <> nil then Heap^.Update;
  158. end;
  159.  
  160. procedure TMyApp.InitMenuBar;
  161. begin
  162.   MenuBar := PMenuBar(RezFile.Get('MainMenu'));
  163. end;
  164.  
  165. procedure TMyApp.InitStatusLine;
  166. var
  167.   R: TRect;
  168. begin
  169.   StatusLine := PHCStatusLine(RezFile.Get('StatusLine'));
  170.   GetExtent(R);
  171.   R.A.Y := R.B.Y - 1;
  172.   StatusLine^.Locate(R);
  173. end;
  174.  
  175. procedure TMyApp.ToggleVideoMode;
  176. var
  177.   NewMode: Word;
  178.   R: TRect;
  179. begin
  180.   NewMode := ScreenMode xor smFont8x8;
  181.   if NewMode and smFont8x8 <> 0 then ShadowSize.X := 1
  182.   else ShadowSize.X := 2;
  183.   SetScreenMode(NewMode);
  184.   GetExtent(R);
  185.   Heap^.MoveTo(R.B.X - 9, R.B.Y - 1);
  186.   Desktop^.GetExtent(R);
  187.   TrashCan^.MoveTo(R.A.X + 1, R.B.Y - 4);
  188.   ConfigRec.Video := ScreenMode and smFont8x8;
  189. end;
  190.  
  191. procedure TMyApp.HandleEvent(var Event: TEvent);
  192. var
  193.   NewDrive: Char;
  194. begin
  195.   inherited HandleEvent(Event);
  196.   if Event.What = evCommand then
  197.   begin
  198.     case Event.Command of
  199.       cmNewWindow:
  200.         begin
  201.           NewDrive := SelectDrive;
  202.           if NewDrive <> ' ' then InsertTreeWindow(NewDrive);
  203.           ClearEvent(Event);
  204.         end;
  205.       cmBeginSearch: BeginSearch;
  206.       cmInstallViewer : InstallViewer;
  207.       cmDisplayOptions : SetDisplayPrefs;
  208.       cmSaveConfig : SaveConfig;
  209.       cmTile : Tile;
  210.       cmCascade : Cascade;
  211.       cmCloseAll: Message(Desktop, evBroadcast, cmCloseAll, nil);
  212.       cmDosShell : DosShell;
  213.       cmRun : RunDosCommand('');
  214.       cmVideoMode: ToggleVideoMode;
  215.       cmExitHere:
  216.         begin
  217.           Message(Desktop, evBroadcast, cmGetCurrentDir, @ExitDir);
  218.           EndModal(cmQuit);
  219.           ClearEvent(Event);
  220.         end;
  221.       cmColorChange: SelectNewColors;
  222.     end;
  223.   end;
  224. end;
  225.  
  226. procedure TMyApp.OutOfMemory;
  227. begin
  228.   MessageBox('There is not enough memory to complete this operation.',
  229.     nil, mfError+mfOKButton);
  230. end;
  231.  
  232. var
  233.   MyApp : TMyApp;
  234.  
  235. begin
  236.   MyApp.Init;
  237.   MyApp.Run;
  238.   MyApp.Done;
  239. end.
  240.